import { useRequest } from "../../../utils/request";
import dayjs from "../../../utils/day";
import { addStrategyHistory } from "../../../utils/history";

Component({
    properties: {},
    data: {},
    methods: {
        onLoad(options) {
            this.request = new useRequest('api/userstrategydetail', {
                data: 'data',
                params: {
                    strategy_id: options.id
                },
                pretreatment: data => {
                    data.time = dayjs.unix(data.create_time).format('YYYY-MM-DD')

                    addStrategyHistory(data)
                    return data
                }
            }, this)

            this.favoriteRequest = new useRequest('api/collectall', {
                params: { type: 3, stragy_id: options.id },
                loading: false,
                hold: true
            }, this)

            this.unFavoriteRequest = new useRequest('api/cancercollectdata', {
                params: { type: 3, stragy_id: options.id },
                loading: false,
                hold: true
            }, this)
        },
        favorite() {
            if (this.data.data.is_collect) {
                this.unFavoriteRequest.run().then(() => {
                    this.setData({
                        ['data.is_collect']: false
                    })
                })
            } else {
                this.favoriteRequest.run().then(() => {
                    this.setData({
                        ['data.is_collect']: true
                    })
                })
            }
        },
    }
});
